package com.another.bidservice.service.impl;

import com.another.bidservice.entity.TCodeRule;
import com.another.common.utils.common.EmptyUtil;
import com.another.common.utils.common.MyException;
import com.another.common.utils.result.ResultEnum;
import com.another.bidservice.utils.generator.GeneratorCodeForMysql;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author : another
 * @version : 1.0
 * @description :
 * @date : 2019/7/26  下午2:57
 */

@Component
public class BaseServiceImpl {

    @Autowired
    private GeneratorCodeForMysql generatorCodeForMysql;

    /**
     * @author Another
     * @description :  生成编号
     * @date 2019/7/26
     * @param tableColumn
     * @param length
     * @param companyId
     * @return java.lang.String
     * @version : 1.0
     */
    public String generateNumber(String tableColumn,int length,String companyId){

        TCodeRule codeRule = new TCodeRule();
        codeRule.setPlatId(companyId);
        codeRule.setSeqTypeId(tableColumn);
        codeRule.setSize(length);
        String number = generatorCodeForMysql.GeneratorCode(codeRule);
        if (EmptyUtil.isEmpty(number)) {
            throw new MyException(ResultEnum.ERROR.getCode(), "生成编号失败!");
        }
        return number;
    }


    public String generateNumber(String tableColumn,int length){

        TCodeRule codeRule = new TCodeRule();
        codeRule.setPlatId("");
        codeRule.setSeqTypeId(tableColumn);
        codeRule.setSize(length);
        String number = generatorCodeForMysql.GeneratorCode(codeRule);
        if (EmptyUtil.isEmpty(number)) {
            throw new MyException(ResultEnum.ERROR.getCode(), "生成编号失败!");
        }
        return number;
    }


    public String generateNumber(String tableColumn){

        TCodeRule codeRule = new TCodeRule();
        codeRule.setPlatId("");
        codeRule.setSeqTypeId(tableColumn);
        codeRule.setSize(1);
        String number = generatorCodeForMysql.GeneratorCode(codeRule);
        if (EmptyUtil.isEmpty(number)) {
            throw new MyException(ResultEnum.ERROR.getCode(), "生成编号失败!");
        }
        return number;
    }
}
